package com.zhima.annotation;

import com.config.JwtTokenConfiguration;
import com.config.ResourceServerConfiguration;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

public class ZhimaOjSecurityImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        Map<String, Object> enableSecurityAttributes = annotationMetadata.getAnnotationAttributes(EnableSecurity.class.getName());
        if ((Boolean) enableSecurityAttributes.getOrDefault("value", true)) {
            return new String[]{JwtTokenConfiguration.class.getName(), ResourceServerConfiguration.class.getName()};
        }
        return new String[]{JwtTokenConfiguration.class.getName()};
    }
}
